package com.commutersconnect.model {

import net.liftweb._
import mapper._
import util._
import common._

/**
 * Companion class for Message.  Provides database access using the Lift Mapper
 * API.
 */
object Message extends Message with LongKeyedMetaMapper[Message] {
  override def dbTableName = "messages"
  override def fieldOrder = List(text)
}

/**
 * A Message is any communication in relation to a Report.  Currently these
 * are not threaded, and are simply kept as a list linked off of Reports.
 */
class Message
  extends LongKeyedMapper[Message]
  with CreatedUpdated with IdPK {

  def getSingleton = Message // Required for Mapper API.

  object text extends MappedString(this, 512) {
    override def validations = {
      valMinLen(1, "No message provided.") _ ::
      valMaxLen(512, "Unforutnately, we can not take messages longer than 512 characters.") _ :: Nil
    }
  }

  object report extends MappedLongForeignKey(this, Report)

  object author extends MappedLongForeignKey(this, User)
}

}

